<template>
  <div>
    <div class="gva-search-box">
      <el-form ref="elSearchFormRef" :inline="true" :model="searchInfo" class="demo-form-inline" :rules="searchRule" @keyup.enter="onSubmit">
      <el-form-item label="创建日期" prop="createdAt">
      <template #label>
        <span>
          创建日期
          <el-tooltip content="搜索范围是开始日期（包含）至结束日期（不包含）">
            <el-icon><QuestionFilled /></el-icon>
          </el-tooltip>
        </span>
      </template>
      <el-date-picker v-model="searchInfo.startCreatedAt" type="datetime" placeholder="开始日期" :disabled-date="time=> searchInfo.endCreatedAt ? time.getTime() > searchInfo.endCreatedAt.getTime() : false"></el-date-picker>
       —
      <el-date-picker v-model="searchInfo.endCreatedAt" type="datetime" placeholder="结束日期" :disabled-date="time=> searchInfo.startCreatedAt ? time.getTime() < searchInfo.startCreatedAt.getTime() : false"></el-date-picker>
      </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
          <el-button icon="refresh" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="gva-table-box">
        <div class="gva-btn-list">
            <el-button type="primary" icon="plus" @click="openDialog">新增</el-button>
            <el-popover v-model:visible="deleteVisible" :disabled="!multipleSelection.length" placement="top" width="160">
            <p>确定要删除吗？</p>
            <div style="text-align: right; margin-top: 8px;">
                <el-button type="primary" link @click="deleteVisible = false">取消</el-button>
                <el-button type="primary" @click="onDelete">确定</el-button>
            </div>
            <template #reference>
                <el-button icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="deleteVisible = true">删除</el-button>
            </template>
            </el-popover>
        </div>
        <el-table
        ref="multipleTable"
        style="width: 100%"
        tooltip-effect="dark"
        :data="tableData"
        row-key="ID"
        @selection-change="handleSelectionChange"
        >
        <el-table-column type="selection" width="55" />
        <el-table-column align="left" label="影片ID" prop="movieId" width="120" />
        <el-table-column align="left" label="抖音剧目ID" prop="albumId" width="120" />
        <el-table-column align="left" label="影片名" prop="title" width="120" />
        <el-table-column align="left" label="总集数" prop="seqNum" width="120" />
        <el-table-column label="竖版封面" width="120">
              <template #default="scope">
                <el-image style="width: 100px; height: 140px" :src="getUrl(scope.row.coverListUrl)" fit="cover"/>
              </template>
          </el-table-column>
        <el-table-column align="left" label="发行年份" prop="year" width="120" />
        <el-table-column align="left" label="短剧更新状态" prop="albumStatus" width="120" >
          <template #default="scope">
                        {{  scope.row.albumStatus==1 ?"未上映": ""}}
                        {{  scope.row.albumStatus==2 ?"更新中": ""}}
                        {{  scope.row.albumStatus==3 ?"已完结": ""}}
          </template>
        </el-table-column>
        <el-table-column align="left" label="短剧推荐语" prop="recommendation" width="120" />
        <!-- <el-table-column align="left" label="短剧简介" prop="desp" width="120" /> -->
        <el-table-column align="left" label="短剧类目标签" prop="tagList" width="120" />
        <!-- <el-table-column align="left" label="资质状态- 1" prop="qualification" width="120" /> -->
        <el-table-column align="left" label="平均单集时长（分钟）" prop="duration" width="120" />
        <el-table-column align="left" label="剧目制作方" prop="productionOrganisation" width="120" />
        <el-table-column align="left" label="导演" prop="director" width="120" />
        <el-table-column align="left" label="制作人" prop="producer" width="120" />
        <el-table-column align="left" label="演员" prop="actor" width="120" />
        <!-- <el-table-column align="left" label="内容梗概" prop="summary" width="120" /> -->
        <el-table-column label="成本配置比例情况" width="120">
              <template #default="scope">
                <el-image style="width: 100px; height: 140px" :src="getUrl(scope.row.costDistributionUriUrl)" fit="cover"/>
              </template>
          </el-table-column>
        <!-- <el-table-column label="承诺书" width="120">
            <template #default="scope">
              <el-image style="width: 100px; height: 140px" :src="getUrl(scope.row.assuranceUriUrl)" fit="cover"/>
            </template>
        </el-table-column> -->
        
        <el-table-column align="left" label="制作成本类型" prop="playletProductionCost" width="120" >
          <template #default="scope">
                        {{  scope.row.playletProductionCost==10 ?"30万以下": ""}}
                        {{  scope.row.playletProductionCost==20 ?"30～100万": ""}}
                        {{  scope.row.playletProductionCost==30 ?"100万以上": ""}}
          </template>
        </el-table-column>
        <el-table-column align="left" label="编剧" prop="screenWriter" width="120" />
        <!-- <el-table-column align="left" label="备案号类型" prop="recordType" width="120" /> -->
        <!-- <el-table-column align="left" label="广电备案号" prop="broadcastRecordNumber" width="120" /> -->
        <!-- <el-table-column align="left" label="被授权小程序" prop="appIdList" width="120" /> -->
        <el-table-column align="left" label="页面绑定状态" prop="schemaBindStatus" width="120" >
          <template #default="scope">
                        {{  scope.row.schemaBindStatus==0 ?"未绑定": ""}}
                        {{  scope.row.schemaBindStatus==1 ?"成功绑定": ""}}
          </template>
        </el-table-column>
        <el-table-column align="left" label="版本号" prop="version" width="120" />
        <el-table-column align="left" label="送审状态" prop="status" width="120" >
          <template #default="scope">
                        {{  scope.row.status==0 ?"未提交": ""}}
                        {{  scope.row.status==1 ?"未提交": ""}}
                        {{  scope.row.status==2 ?"已提交": ""}}
                        {{  scope.row.status==3 ?"已审出": ""}}
          </template>
        </el-table-column>
        <el-table-column align="left" label="审核状态" prop="auditStatus" width="120" >
          <template #default="scope">
                        {{  scope.row.auditStatus==0 ?"未审核": ""}}
                        {{  scope.row.auditStatus==99 ?"未审核": ""}}
                        {{  scope.row.auditStatus==98 ?"审核中": ""}}
                        {{  scope.row.auditStatus==1 ?"不可播放": ""}}
                        {{  scope.row.auditStatus==2 ?"可播放": ""}}
          </template>
        </el-table-column>
        <el-table-column align="left" label="审核备注" prop="auditMsg" width="120" />
        <el-table-column align="left" label="短剧版本上下线状态" prop="playletStatus" width="120" >
          <template #default="scope">
                        {{  scope.row.playletStatus==0 || scope.row.playletStatus==''?"上线": ""}}
                        {{  scope.row.playletStatus==1 ?"下线": ""}}
                        {{  scope.row.playletStatus==2 ?"未上线": ""}}
          </template>
        </el-table-column>
        <el-table-column align="left" label="创建人" prop="createUid" width="120" />
         <el-table-column align="left" label="创建时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.createTime) }}</template>
         </el-table-column>
        <el-table-column align="left" label="更新人" prop="updateUid" width="120" />
         <el-table-column align="left" label="更新时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.updateTime) }}</template>
         </el-table-column>
        <el-table-column align="left" label="操作" fixed="right" width="120">
            <template #default="scope">
            <el-button type="primary" link class="table-button" @click="getDetails(scope.row)">
                <el-icon style="margin-right: 5px"><InfoFilled /></el-icon>
                查看详情
            </el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="updateMoviesAuditTtFunc(scope.row,1)">剧目修改</el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="playLetVideoEditRow(scope.row,2)">剧集变更</el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="playLetVideoReviewRow(scope.row)">版本送审</el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="getPlayLetVideoResultRow(scope.row)">查询结果</el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="onlineRow(scope.row,2)">版本上线</el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="onlineRow(scope.row,3)">版本下线</el-button>
            </template>
        </el-table-column>
        </el-table>
        <div class="gva-pagination">
            <el-pagination
            layout="total, sizes, prev, pager, next, jumper"
            :current-page="page"
            :page-size="pageSize"
            :page-sizes="[10, 30, 50, 100]"
            :total="total"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
            />
        </div>
    </div>
    <el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="type==='create'?'添加':'修改'" destroy-on-close>
      <el-scrollbar height="500px">
          <el-form :model="formData" label-position="right" ref="elFormRef" :rules="rule" label-width="120px">
            <el-form-item label="影片ID:"  prop="movieId" >
              <el-input v-model.number="formData.movieId" :clearable="true" placeholder=""   :disabled = "true"/>
            </el-form-item>
            <el-form-item label="影片名:"  prop="title" >
              <el-input v-model="formData.title" :clearable="true"  placeholder=""  :disabled = "true"/>
            </el-form-item>
            <el-form-item label="总集数:"  prop="seqNum" >
              <el-input v-model="formData.seqNum" :clearable="true" placeholder=""  :disabled = "true"/>
            </el-form-item>
            <el-form-item label="竖版封面内容:"  prop="coverListUrl" >
                <template #default="scope">
                  <el-image style="width: 100px; height: 140px" :src="getUrl(formData.coverListUrl)" fit="cover"/>
                </template>
            </el-form-item>
            <el-form-item label="发行年份:"  prop="year" >
              <el-input v-model.number="formData.year" :clearable="true" placeholder="请输入发行年份" />
            </el-form-item>
            <el-form-item label="短剧更新状态"  prop="albumStatus" >
              <el-radio-group v-model="formData.albumStatus">
                <el-radio :label="1">未上映</el-radio>
                <el-radio :label="2">更新中</el-radio>
                <el-radio :label="3">已完结</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="短剧推荐语:"  prop="recommendation" >
              <el-input v-model="formData.recommendation" :clearable="true"  placeholder="最多12字" />
            </el-form-item>
            <el-form-item label="短剧简介:"  prop="desp" >
              <el-input v-model="formData.desp" :clearable="true"  placeholder="最多200字" />
            </el-form-item>
            <el-form-item label="短剧类目标签:"  prop="tagList" >
              <el-input v-model="formData.tagList" :clearable="true"  placeholder="最多选3个,逗号“,”分割" />
            </el-form-item>
            <el-form-item label="平均单集时长:"  prop="duration" >
              <el-input v-model.number="formData.duration" :clearable="true" placeholder="平均单集时长，单位分钟" />
            </el-form-item>
            <el-form-item label="剧目制作方:"  prop="productionOrganisation" >
              <el-input v-model="formData.productionOrganisation" :clearable="true"  placeholder="剧目制作方" />
            </el-form-item>
            <el-form-item label="导演:"  prop="director" >
              <el-input v-model="formData.director" :clearable="true"  placeholder="导演" />
            </el-form-item>
            <el-form-item label="制作人:"  prop="producer" >
              <el-input v-model="formData.producer" :clearable="true"  placeholder="制作人" />
            </el-form-item>
            <el-form-item label="演员:"  prop="actor" >
              <el-input v-model="formData.actor" :clearable="true"  placeholder="演员" />
            </el-form-item>
            <el-form-item label="编剧:"  prop="screenWriter" >
              <el-input v-model="formData.screenWriter" :clearable="true"  placeholder="编剧(选填)" />
            </el-form-item>
            <el-form-item label="内容梗概:"  prop="summary" >
              <el-input v-model="formData.summary" :clearable="true"  placeholder="内容梗概（1000 汉字以内）" />
            </el-form-item>
            <el-form-item label="成本配置比例情况:"  prop="costDistributionUriUrl" >
                <SelectImage
                 v-model="formData.costDistributionUriUrl"
                 file-type="image"
                 :movie-id="formData.movieId"
                />
            </el-form-item>
            <el-form-item label="承诺书:"  prop="assuranceUriUrl" >
                <SelectImage
                 v-model="formData.assuranceUriUrl"
                 file-type="image"
                 :movie-id="formData.movieId"
                />
            </el-form-item>
            <el-form-item label="短剧更新状态"  prop="playletProductionCost" >
              <el-radio-group v-model="formData.playletProductionCost">
                <el-radio :label="10">30万以下</el-radio>
                <el-radio :label="20">30～100万</el-radio>
                <el-radio :label="30">100万以上</el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="备案号类型(选填)"  prop="recordType" >
              <el-radio-group v-model="formData.recordType">
                <el-radio :label="10">普通备案号</el-radio>
                <el-radio :label="20">重点备案号</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="广电备案号:"  prop="broadcastRecordNumber" >
              <el-input v-model="formData.broadcastRecordNumber" :clearable="true"  placeholder="广电备案号（选填）" />
            </el-form-item>
          </el-form>
      </el-scrollbar>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="enterDialog">确 定</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog v-model="detailShow" style="width: 800px" lock-scroll :before-close="closeDetailShow" title="查看详情" destroy-on-close>
      <el-scrollbar height="550px">
        <el-descriptions column="1" border>
                <el-descriptions-item label="影片ID">
                        {{ formData.movieId }}
                </el-descriptions-item>
                <el-descriptions-item label="剧目ID">
                        {{ formData.albumId }}
                </el-descriptions-item>
                <el-descriptions-item label="影片名">
                        {{ formData.title }}
                </el-descriptions-item>
                <el-descriptions-item label="总集数">
                        {{ formData.seqNum }}
                </el-descriptions-item>
                <el-descriptions-item label="竖版封面内容md5">
                        {{ formData.coverList }}
                </el-descriptions-item>
                <el-descriptions-item label="发行年份">
                        {{ formData.year }}
                </el-descriptions-item>
                <el-descriptions-item label="短剧更新状态">
                        {{ formData.albumStatus }}
                </el-descriptions-item>
                <el-descriptions-item label="短剧推荐语">
                        {{ formData.recommendation }}
                </el-descriptions-item>
                <el-descriptions-item label="短剧简介">
                        {{ formData.desp }}
                </el-descriptions-item>
                <el-descriptions-item label="短剧类目标签">
                        {{ formData.tagList }}
                </el-descriptions-item>
                <el-descriptions-item label="资质状态- 1">
                        {{ formData.qualification }}
                </el-descriptions-item>
                <el-descriptions-item label="平均单集时长，单位分钟">
                        {{ formData.duration }}
                </el-descriptions-item>
                <el-descriptions-item label="剧目制作方">
                        {{ formData.productionOrganisation }}
                </el-descriptions-item>
                <el-descriptions-item label="导演">
                        {{ formData.director }}
                </el-descriptions-item>
                <el-descriptions-item label="制作人">
                        {{ formData.producer }}
                </el-descriptions-item>
                <el-descriptions-item label="演员">
                        {{ formData.actor }}
                </el-descriptions-item>
                <el-descriptions-item label="内容梗概">
                        {{ formData.summary }}
                </el-descriptions-item>
                <el-descriptions-item label="成本配置比例情况">
                        {{ formData.costDistributionUri }}
                </el-descriptions-item>
                <el-descriptions-item label="承诺书">
                        {{ formData.assuranceUri }}
                </el-descriptions-item>
                <el-descriptions-item label="制作成本类型">
                        {{ formData.playletProductionCost }}
                </el-descriptions-item>
                <el-descriptions-item label="编剧">
                        {{ formData.screenWriter }}
                </el-descriptions-item>
                <el-descriptions-item label="备案号类型">
                        {{ formData.recordType }}
                </el-descriptions-item>
                <el-descriptions-item label="广电备案号">
                        {{ formData.broadcastRecordNumber }}
                </el-descriptions-item>
                <el-descriptions-item label="被授权小程序">
                        {{ formData.appIdList }}
                </el-descriptions-item>
                <el-descriptions-item label="页面绑定">
                        {{ formData.schemaBindStatus }}
                </el-descriptions-item>
                <el-descriptions-item label="版本号">
                        {{ formData.version }}
                </el-descriptions-item>
                <el-descriptions-item label="送审状态">
                        {{ formData.status }}
                </el-descriptions-item>
                <el-descriptions-item label="审核状态">
                        {{ formData.auditStatus }}
                </el-descriptions-item>
                <el-descriptions-item label="审核备注">
                        {{ formData.auditMsg }}
                </el-descriptions-item>
                <el-descriptions-item label="短剧版本上下线状态">
                        {{ formData.playletStatus }}
                </el-descriptions-item>
        </el-descriptions>
      </el-scrollbar>
    </el-dialog>

    <el-dialog v-model="resultShow" style="width: 800px" lock-scroll :before-close="closeResultShow" title="审核结果" destroy-on-close>
      <el-scrollbar height="550px">
        <el-descriptions column="1" border>
  
                <el-descriptions-item label="剧目ID">
                        {{ resultData.albumId }}
                </el-descriptions-item>
                <el-descriptions-item label="版本号">
                        {{ resultData.version }}
                </el-descriptions-item>
                <el-descriptions-item label="送审状态">
                        {{  resultData.status==0 ?"未提交": ""}}
                        {{  resultData.status==1 ?"未提交": ""}}
                        {{  resultData.status==2 ?"已提交": ""}}
                        {{  resultData.status==3 ?"已审出": ""}}
                </el-descriptions-item>
                <el-descriptions-item label="审核状态">
                        {{  resultData.auditStatus==99 ?"未审核": ""}}
                        {{  resultData.auditStatus==98 ?"审核中": ""}}
                        {{  resultData.auditStatus==1 ?"不可播放": ""}}
                        {{  resultData.auditStatus==2 ?"可播放": ""}}
                </el-descriptions-item>
                <el-descriptions-item label="审核备注">
                        {{ resultData.auditMsg }}
                </el-descriptions-item>

        </el-descriptions>
        <div class="gva-table-box">
                        <el-table
                style="width: 100%"
                tooltip-effect="dark"
                :data="resultTableData"
                >
                <el-table-column align="left" label="剧集标题" prop="title" width="80" />
                <!-- <el-table-column align="left" label="集数" prop="seq" width="120" /> -->
                <el-table-column align="left" label="剧集id" prop="episodeId" width="180" />
                <el-table-column align="left" label="版本号" prop="version" width="80" />
                <el-table-column align="left" label="状态" prop="status" width="80" >
                  <template #default="scope">
                    {{  scope.row.status==0 ?"未提交": ""}}
                    {{  scope.row.status==1 ?"未提交": ""}}
                    {{  scope.row.status==2 ?"已提交": ""}}
                    {{  scope.row.status==3 ?"已审出": ""}}
                  </template>
                </el-table-column>
                <el-table-column align="left" label="审核状态" prop="auditStatus" width="120" >
                  <template #default="scope">
                    {{  scope.row.auditStatus==99 ?"未审核": ""}}
                    {{  scope.row.auditStatus==98 ?"审核中": ""}}
                    {{  scope.row.auditStatus==1 ?"不可播放": ""}}
                    {{  scope.row.auditStatus==2 ?"可播放": ""}}
                  </template>
                </el-table-column>
                <el-table-column align="left" label="审核备注" prop="auditMsg" width="200" />
                </el-table>
              </div>
      </el-scrollbar>
    </el-dialog>
  </div>
</template>

<script setup>
import {
  createMoviesAuditTt,
  deleteMoviesAuditTt,
  deleteMoviesAuditTtByIds,
  updateMoviesAuditTt,
  findMoviesAuditTt,
  getMoviesAuditTtList,
  playLetVideoReview,
  playLetAlbumOnline,
  playLetAlbumFetchSet,
} from '@/api/moviesAuditTt'
import { getUrl } from '@/utils/image'

// 图片选择组件
import SelectImage from '@/components/selectImage/selectImage.vue'

import {
  findMovieAuto,
} from '@/api/movieAuto'

// 全量引入格式化工具 请按需保留
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'

defineOptions({
    name: 'MoviesAuditTt'
})
const props = defineProps({
  row: {
    default: function() {
      return {}
    },
    type: Object
  }
})

// 自动化生成的字典（可能为空）以及字段
const formData = ref({
        movieId: props.row.ID,
        albumId: 0,
        title: props.row.name,
        seqNum: 0,
        coverList: '',
        coverListUrl: '',
        year: 0,
        albumStatus: 0,
        recommendation: '',
        desp: '',
        tagList: '',
        qualification: 1,
        duration: 0,
        productionOrganisation: '',
        director: '',
        producer: '',
        actor: '',
        summary: '',
        costDistributionUri: '',
        costDistributionUriUrl: '',
        assuranceUri: '',
        assuranceUriUrl: '',
        playletProductionCost: 0,
        screenWriter: '',
        recordType: 0,
        broadcastRecordNumber: '',
        appIdList: '',
        schemaBindStatus: 0,
        version: 0,
        status: 0,
        auditStatus: 0,
        auditMsg: '',
        playletStatus: 0,
        editType:1,
        })


// 验证规则
const rule = reactive({
})

const searchRule = reactive({
  createdAt: [
    { validator: (rule, value, callback) => {
      if (searchInfo.value.startCreatedAt && !searchInfo.value.endCreatedAt) {
        callback(new Error('请填写结束日期'))
      } else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
        callback(new Error('请填写开始日期'))
      } else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
        callback(new Error('开始日期应当早于结束日期'))
      } else {
        callback()
      }
    }, trigger: 'change' }
  ],
})

const elFormRef = ref()
const elSearchFormRef = ref()

//审核结果 
const resultData = ref({
  albumId : 0,
    version : 0,
    status : 0,
    auditStatus : 0,
    auditMsg : '',
})

// =========== 表格控制部分 ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({
  movieId: props.row.ID,
})

const resultTableData = ref([])

// 重置
const onReset = () => {
  searchInfo.value = {}
  searchInfo.value.movieId = props.row.ID
  getTableData()
}

// 搜索
const onSubmit = () => {
  elSearchFormRef.value?.validate(async(valid) => {
    if (!valid) return
    page.value = 1
    pageSize.value = 10
    getTableData()
  })
}

// 分页
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}

// 修改页面容量
const handleCurrentChange = (val) => {
  page.value = val
  getTableData()
}

// 查询
const getTableData = async() => {
  const table = await getMoviesAuditTtList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
  if (table.code === 0) {
    tableData.value = table.data.list
    total.value = table.data.total
    page.value = table.data.page
    pageSize.value = table.data.pageSize
  }
}

getTableData()

// ============== 表格控制部分结束 ===============

// 获取需要的字典 可能为空 按需保留
const setOptions = async () =>{
}

// 获取需要的字典 可能为空 按需保留
setOptions()


// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
    multipleSelection.value = val
}

// 删除行
const deleteRow = (row) => {
    ElMessageBox.confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
            deleteMoviesAuditTtFunc(row)
        })
    }


// 批量删除控制标记
const deleteVisible = ref(false)

// 多选删除
const onDelete = async() => {
      const ids = []
      if (multipleSelection.value.length === 0) {
        ElMessage({
          type: 'warning',
          message: '请选择要删除的数据'
        })
        return
      }
      multipleSelection.value &&
        multipleSelection.value.map(item => {
          ids.push(item.ID)
        })
      const res = await deleteMoviesAuditTtByIds({ ids })
      if (res.code === 0) {
        ElMessage({
          type: 'success',
          message: '删除成功'
        })
        if (tableData.value.length === ids.length && page.value > 1) {
          page.value--
        }
        deleteVisible.value = false
        getTableData()
      }
    }

// 行为控制标记（弹窗内部需要增还是改）
const type = ref('')

// 更新行
const updateMoviesAuditTtFunc = async(row,editType) => {
    const res = await findMoviesAuditTt({ ID: row.ID })
    type.value = 'update'
    if (res.code === 0) {
        formData.value = res.data.removiesAuditTt
        formData.value.editType =editType
        dialogFormVisible.value = true
    }
}
const getMovieAuto = async() => {
  const res = await findMovieAuto({ ID: props.row.ID})
    if (res.code === 0) {
        formData.value.seqNum = res.data.removie.totalCnt
        formData.value.coverListUrl = res.data.removie.imgUrl
        formData.value.recommendation = res.data.removie.recommend
        formData.value.desp = res.data.removie.intro
        formData.value.albumStatus = res.data.removie.fullFlag==1?3:res.data.removie.fullFlag
    }
}
getMovieAuto()


// 删除行
const deleteMoviesAuditTtFunc = async (row) => {
    const res = await deleteMoviesAuditTt({ ID: row.ID })
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '删除成功'
            })
            if (tableData.value.length === 1 && page.value > 1) {
            page.value--
        }
        getTableData()
    }
}
//送审操作
const playLetVideoReviewRow = (row) => {
    ElMessageBox.confirm('确定要送审吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
        playLetVideoReviewFunc(row)
        })
}
   // 提交送审
const playLetVideoReviewFunc = async (row) => {
    const res = await playLetVideoReview({ ID: row.ID })
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '送审成功'
            })
      }
      getTableData()
}
// 抖音-更新剧集操作
const playLetVideoEditRow = (row,editType) => {
    ElMessageBox.confirm('确定要更新剧集吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
      playLetVideoEditFunc(row,editType)
        })
}
   // 提交-更新剧集
const playLetVideoEditFunc = async (row,editType) => {
  let data = {}
  data.ID= row.ID 
  data.editType= editType 
    const res = await updateMoviesAuditTt(data)
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '更新成功'
            })
      }
      getTableData()
}
// 弹窗控制标记
const dialogFormVisible = ref(false)


// 查看详情控制标记
const detailShow = ref(false)


// 打开详情弹窗
const openDetailShow = () => {
  detailShow.value = true
}


// 打开详情
const getDetails = async (row) => {
  // 打开弹窗
  const res = await findMoviesAuditTt({ ID: row.ID })
  if (res.code === 0) {
    formData.value = res.data.removiesAuditTt
    openDetailShow()
  }
}


// 关闭详情弹窗
const closeDetailShow = () => {
  detailShow.value = false
  formData.value = {
          movieId: props.row.ID,
          albumId: 0,
          title: props.row.name,
          seqNum: 0,
          coverList: '',
          coverListUrl: '',
          year: 0,
          albumStatus: 0,
          recommendation: '',
          desp: '',
          tagList: '',
          qualification: 0,
          duration: 0,
          productionOrganisation: '',
          director: '',
          producer: '',
          actor: '',
          summary: '',
          costDistributionUri: '',
          costDistributionUriUrl: '',
          assuranceUri: '',
          assuranceUriUrl: '',
          playletProductionCost: 0,
          screenWriter: '',
          recordType: 0,
          broadcastRecordNumber: '',
          appIdList: '',
          schemaBindStatus: 0,
          version: 0,
          status: 0,
          auditStatus: 0,
          auditMsg: '',
          playletStatus: 0,
          createUid: 0,
          createTime: new Date(),
          updateUid: 0,
          updateTime: new Date(),
          }
}

//审核结果查询
// 查看结果详情控制标记
const resultShow = ref(false)

// 打开结果详情弹窗
const openResultShow = () => {
  resultShow.value = true
}

// 打开结果详情
const getPlayLetVideoResultRow = async (row) => {
  // 打开弹窗
  const res = await playLetAlbumFetchSet({ ID: row.ID })
  if (res.code === 0) {
    resultData.value = res.data.albumFetch
    resultTableData.value = res.data.albumFetch.list
    openResultShow()
  }
}
// 关闭审核弹窗
const closeResultShow = () => {
  resultShow.value = false
}

// 打开弹窗
const openDialog = () => {
    type.value = 'create'
    dialogFormVisible.value = true
}

// 关闭弹窗
const closeDialog = () => {                                                                   
    dialogFormVisible.value = false
    formData.value = {
        movieId: props.row.ID,
        albumId: 0,
        title: props.row.name,
        seqNum: 0,
        coverList: '',
        coverListUrl: '',
        year: 0,
        albumStatus: 0,
        recommendation: '',
        desp: '',
        tagList: '',
        qualification: 0,
        duration: 0,
        productionOrganisation: '',
        director: '',
        producer: '',
        actor: '',
        summary: '',
        costDistributionUriUrl: '',
        assuranceUriUrl: '',
        playletProductionCost: 0,
        screenWriter: '',
        recordType: 0,
        broadcastRecordNumber: '',
        appIdList: '',
        schemaBindStatus: 0,
        version: 0,
        status: 0,
        auditStatus: 0,
        auditMsg: '',
        playletStatus: 0,
        }
    getMovieAuto()

}
// 弹窗确定
const enterDialog = async () => {
     elFormRef.value?.validate( async (valid) => {
             if (!valid) return
              let res
              console.log(formData.value)
              switch (type.value) {
                case 'create':
                  res = await createMoviesAuditTt(formData.value)
                  break
                case 'update':
                  res = await updateMoviesAuditTt(formData.value)
                  break
                default:
                  res = await createMoviesAuditTt(formData.value)
                  break
              }
              if (res.code === 0) {
                ElMessage({
                  type: 'success',
                  message: '创建/更改成功'
                })
                closeDialog()
                getTableData()
              }
      })
}
// 上线，下线-操作
const onlineRow = (row,operate) => {
    ElMessageBox.confirm('确定要处理吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
      playLetAlbumOnlineFunc(row,operate)
        })
    }
// 上线，下线处理
const playLetAlbumOnlineFunc = async (row,operate) => {
    const res = await playLetAlbumOnline({ ID: row.ID ,operate:operate})
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '操作成功'
            })
        getTableData()
    }
}

</script>

<style>

</style>
